package com.hh.springboot.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
public class FileController {
    private static final String BASE_DIR = "D:\\上传文件\\";

    @RequestMapping("/file")
    public void upload(@RequestParam MultipartFile file) {
        //文件名
        String filename = file.getOriginalFilename();
        File uploadFile = new File(BASE_DIR + filename);
        if (!uploadFile.getParentFile().exists()){
            uploadFile.getParentFile().mkdirs();
        }
        try {
            file.transferTo(uploadFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
